#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read()
{
	int res=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){res=(res<<1)+(res<<3)+(c^48);c=getchar();}
	return res*f;
}
void write(int x)
{
	if(x<0)x=-x,putchar('-');
	if(x>9)write(x/10);
	putchar(x%10+'0');
}
struct node
{
	int l,r;
	bool operator<(const node &a)const{return r<a.r;}	
}q[500005];
int n,m;
int a[500005];
namespace Nene
{
	int t[500005<<2];
	#define ls (root<<1)
	#define rs (root<<1|1)
	#define mid (l+r>>1)
	void insert(int x,int v,int root=1,int l=0,int r=n)
	{
		if(l==r)
		{
			t[root]=v;
			return;
		}
		if(x<=mid) insert(x,v,ls,l,mid);
		else insert(x,v,rs,mid+1,r);
		t[root]=min(t[ls],t[rs]);
	}
	int query(int x,int y,int root=1,int l=0,int r=n)
	{
		if(l>=x&&r<=y) return t[root];
		int res=1e18;
		if(x<=mid) res=min(res,query(x,y,ls,l,mid));
		if(y>mid) res=min(res,query(x,y,rs,mid+1,r));
		return res;
	}
}
using namespace Nene;
signed main()
{
	freopen("gonna.in","r",stdin);
	freopen("gonna.out","w",stdout);
	n=read();
	for(int i=1;i<=n;i++) a[i]=read();
	m=read();
	for(int i=1;i<=m;i++) q[i].l=read(),q[i].r=read();
	sort(q+1,q+m+1);
	memset(t,0x3f,sizeof t);
	insert(0,0);
	int cur=1,last=0;
	for(int i=1;i<=n;i++)
	{
		int maxn=0;
		while(q[cur].r==i) maxn=max(maxn,q[cur].l),++cur;
		int f=query(last,i-1)+a[i];
		insert(i,f);
		last=max(last,maxn);
	}
	write(query(last,n));
	return 0;
}
